<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>

  <div id="app">
    姓：<input v-model="fitrstName" type="text"><br>
    名：<input v-model="lastName" type="text"><br>
    <p>姓名：{{ fullName }}</p>
    <button @click="changeFullName">修改姓名</button>
  </div>
  <script src="./js/vue.js"></script>
  <script>
    const app = new Vue({
      el: '#app',
      data: {
        fitrstName: '',
        lastName: ''
      },
      computed: {
        // 计算属性简写
        // fullName() {
        //   return this.fitrstName + this.lastName
        // }

        // 计算属性完整写法
        fullName: {
          get() {
            return this.fitrstName + this.lastName
          },
          set(value) {
            this.fitrstName = value.split(' ')[0]
            this.lastName = value.split(' ')[1]
          }
        }
      },
      methods: {
        changeFullName() {
          this.fullName = '刘 玄德'
        }
      }
    })
  </script>
</body>

</html>